type HierarchyNode = {
    name: string, children: HierarchyNode[], uuid: number
}
let index = 0;
function getHierarchyData(gameobject: GameObject): HierarchyNode {
    if(!gameobject.id){
        gameobject.id = "gameObject"+index;
        index++;
    }
    let name = gameobject.id; 
    const children = [];
    if (!gameobject.prefabUrl) {
        for (let child of gameobject.children) {
            children.push(getHierarchyData(child));
        }
    } else {
        name += "(prefab)";
    }
    return { name, children, uuid: gameobject.uuid }
}

type behaviourData = {
    uuid:number,
    name: string,
    properties: { key: string, defaultValue: any, value: any }[]
}

type inspectorData = {
    uuid:number,
    name: string,
    behaviours: behaviourData[]
}

function getInspectorData(gameobject: GameObject): inspectorData {
    let name = gameobject.id ? gameobject.id : "gameobject";
    const uuid = gameobject.uuid;
    const behaviours: behaviourData[] = [];

    for (let child of gameobject.behaviours) {
        const name = child.constructor.name;
        const behaviourproperties = (child.constructor as any).properties || [];
        const properties = behaviourproperties.map(p => {
            return {
                key: p.key, defaultValue: p.defaultValue, value: child[p.key]
            }
        })
        const uuid = child.uuid;
        behaviours.push({ name, properties, uuid });
    }

    return { uuid,name, behaviours }
}